﻿using Ducu.BLL.Entity;
using Ducu.GLB.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ducu.SRV.Query
{
    public static class OnPlan
    {
        /// <summary>
        /// Do not include those still due to take effect
        /// </summary>
        public static IQueryable<Plan> NoDue(this IQueryable<Plan> source)
        {
            return source
                .Where(p => p.From < DateTime.Now)
                ;
        }

        /// <summary>
        /// Do not include those has been expired
        /// </summary>
        public static IQueryable<Plan> NotExpire(this IQueryable<Plan> source)
        {
            return source
                .Where(p => p.To > DateTime.Now.AddDays(-1))
                ;
        }

        public static IQueryable<Plan> NeedSupervisors(this IQueryable<Plan> source)
        {
            return source.Where(p => p.Supervisors.Count < p.MaxNumberOfSupervisors);
        }

        public static IQueryable<Plan> MyFulfil(this IQueryable<Plan> source,
            User vower)
        {
            return source.Where(p => p.Vower == vower);
        }

        public static IQueryable<Plan> MySupervisor(this IQueryable<Plan> source,
            User supervisor)
        {
            return source.Where(p => p.Supervisors.Contains(supervisor));
        }

        public static IQueryable<Plan> Keyword(this IQueryable<Plan> source,
            Keyword keyword)
        {
            return source.Where(p => p.KeyWords.Contains(keyword));
        }

    }
}
